﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.ComponentModel.DataAnnotations;

namespace AirControlATV.Core
{
    public static class EnumHelper
    {
        public static string GetDisplayValue(this Enum enumValue)
        {
            var attr = enumValue.GetAttribute<DisplayAttribute>();

            if (attr == null)
                return null;

            return attr.Name;
        }

        public static T GetAttribute<T>(this Enum enumValue) where T : Attribute
        {
            return enumValue
                .GetType()
                .GetTypeInfo()
                .GetDeclaredField(enumValue.ToString())
                .GetCustomAttribute<T>();
        }
    }
}
